package com.wn.main.navigator

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.WindowInsets
import android.widget.FrameLayout

/**
 * @Author: wn
 * @Date: 2024/9/9 16:55
 * @Description: 处理 Navigation 重建问题
 */
class WindowFrameLayout(context: Context, attributeSet: AttributeSet? = null, defStyle: Int = 0) :
  FrameLayout(context, attributeSet, defStyle) {


  override fun addView(child: View?) {
    super.addView(child)
    requestApplyInsets()
  }

  override fun dispatchApplyWindowInsets(insets: WindowInsets?): WindowInsets {
    var windowInsets = super.dispatchApplyWindowInsets(insets)
    if (insets?.isConsumed == false) {
      val count = childCount
      for (i in 0 until count) {
        windowInsets = getChildAt(i).dispatchApplyWindowInsets(insets)
      }
    }
    return windowInsets
  }
}